package com.test.mapper;

import com.test.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 宋建华
 * @return
 * @date 2023-12-26
 */
@Mapper
public interface UserMapper {

    @Insert("insert into `user`(username,password,name ,phone ,email ,address ,avatar) " +
            "values(#{username},#{password},#{name},#{phone},#{email},#{address},#{avatar})")
    void insertUser(User user);

    @Update("update `user` set username=#{username},password=#{password},name=#{name},phone=#{phone},email=#{email}," +
            "address=#{address},avatar=#{avatar} where id = #{id}")
    void updateUser(User user);

    @Delete("delete from `user` where id =#{id}")
    void deleteUser(Integer id);

    @Delete({
            "<script>",
            "DELETE FROM `user` WHERE id IN",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    void deleteUsers(@Param("ids") List<Integer> ids);

    @Select("select * from `user` order by id desc")
    List<User> selectAll();

    @Select("select * from `user` where id=#{id}")
    User selectAllByid(Integer id);

    @Select("select * from `user` where name =#{name}")
    List<User> selectListName(String name);

    @Select("select * from `user` where name =#{name} and id=#{id}")
    List<User> selectByMore(@Param("name") String name, @Param("id") Integer id);

    @Select("select * from `user` where username like concat('%',#{username},'%') or name like concat ('%',#{name},'%')")
    List<User> selectByMo(@Param("username") String username, @Param("name") String name);

    @Select("select * from `user` where username =#{username}")
    User selectByUsername(String username);
}
